package br.com.statizo.financeiro.domain.entity.impl;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import br.com.statizo.financeiro.domain.enums.ColorConfigType;

@Entity
@Table(name="tb_color_config")
public class ColorConfig extends EntidadeAbstrata{
	
	private static final long serialVersionUID = 1L;

	@Column(name="color_type")
	@Enumerated(EnumType.ORDINAL)
	@Id
	private ColorConfigType id;

	@Column(name="bg_red")
	private int bgRed;
	
	@Column(name="bg_green")
	private int bgGreen;
	
	@Column(name="bg_blue")
	private int bgBlue;
	
	public ColorConfig(){}
	public ColorConfig(ColorConfigType type){
		this.id = type;
	}
	
	@Override
	public Serializable getId() {
		return id;
	}
	
	@Transient
	public int[] getRGB(){
		return new int[]{bgRed, bgGreen, bgBlue};
	}
	
	@Transient
	public int[] getDefaultRGB(){
		return id.getDefaultRGB();
	}

	@Transient
	public ColorConfigType getType(){
		return id;
	}
	
	@Transient
	public void setBackground(int[] rgb){
		this.bgRed = rgb[0];
		this.bgGreen = rgb[1];
		this.bgBlue = rgb[2];
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ColorConfig other = (ColorConfig) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
}